package com.shipwe.loans.ui.adapter

import android.graphics.Color
import androidx.recyclerview.widget.RecyclerView
import com.shipwe.adapter.ShipweRecyclerViewAdapter
import com.shipwe.adapter.ShipweViewHolderHelper
import com.shipwe.loans.R
import org.json.JSONObject

/**
 * Shipwe
 * @Author wwdeng
 * @CreateTime: 2024/11/25 14:42
 * @Annotation：贷款申请 选择时间 适配器
 */
class ApplyDurationAdapter(recyclerView: RecyclerView?) : ShipweRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.apply_duration_item) {
    override fun setItemChildListener(helper: ShipweViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.durationItem) //点击Item
    }

    override fun fillData(helper: ShipweViewHolderHelper, position: Int, model: JSONObject) {
        val durationItem = helper.getTextView(R.id.durationItem)
        durationItem.text = String.format(mContext.getString(R.string.loan_apply_days),model.optString("day"))

        if (model.optBoolean("isEnabled",true)){//可选
            if (model.optBoolean("isSelect",false)){
                durationItem.setBackgroundResource(R.drawable.btn_circle_selector_ff7543ff)
                durationItem.setTextColor(Color.parseColor("#FFFFFF"))
            } else {
                durationItem.setBackgroundResource(R.drawable.circle_fff6f6f6)
                durationItem.setTextColor(Color.parseColor("#FF16181D"))
            }
        } else {//不可选
            durationItem.setBackgroundResource(R.drawable.circle_fff6f6f6)
            durationItem.setTextColor(Color.parseColor("#FF16181D"))
        }
    }
}